﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using My.ExcelToData.ExcelDatas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace My.ExcelToData.Controllers
{
    [Microsoft.AspNetCore.Mvc.Route("api/app/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "ExcelController")] // 自定义swagger 3/3 将此控制器归为 Excel
    public class ExcelController: ExcelToDataController
    {
        private readonly IExcelDataAppService _excelImportAppService;

        public ExcelController(IExcelDataAppService excelImportAppService)
        {
            this._excelImportAppService = excelImportAppService;
        }


        [HttpPost("import")]
        public async Task<IActionResult> ImportExcel(IFormFile file)
        {
            var id = await _excelImportAppService.ImportExcelAsync(file);
            return Ok(id);
        }

        [HttpGet("{id}")]
        public async Task<IActionResult> GetExcelData(Guid id)
        {
            var dataTable = await _excelImportAppService.GetDataTableAsync(id);
            return Ok(dataTable);
        }
    }
}
